var caregiverSendOrdersStandardArray = [];
var loginedUser = null;

$(function() {
	$('#vue_vm_list div').hide();
	
	loginedUser = getLoginedUser();
	$('#subjectRoomName').text(loginedUser.subjectRoomName);
	
	load_caregiverSendOrdersStandard_select();
});

var caregiver = {
	caregiverId: '',
	subjectRoomId: getLoginedUser().subjectRoomId,
	name: '',
	sex: '',
	cardId: '',
	phoneNumber: '',
	birthday: '',
	liveAddress: '',
	entryTime: '',
	contractTime: '',
	photoUrl: '',
	status: '',
	createTime: '',
	updateTime: '',
	createId: getLoginedUser()? getLoginedUser().staffId: '',
	updateId: getLoginedUser()? getLoginedUser().staffId: '',
	remark: '',
	personType: '',
	personTypeName: '',
};

function load_caregiverSendOrdersStandard_select() {
	findAll_basic(path+'/caregiverSendOrdersStandard/findAll', function(response) {
		caregiverSendOrdersStandardArray = response.data;
		
		loadCaregiverBySubjectRoomId(loginedUser.subjectRoomId);
	});
}

function loadCaregiverBySubjectRoomId(subjectRoomId) {
	if($('#vue_vm_list').length==0) {return;}
	$('#vue_vm_list div').hide();
	
	find_basic_by_json(path+'/caregiver/findBySubjectRoomId', {subjectRoomId: subjectRoomId}, function(response) {
		$('#vue_vm_list').html(gl_vue_vm_list_html);
		
		new Vue({
			el: '#vue_vm_list',
			data: {
				todos: response.data
			},
			methods: {
				update_save:function(todo) {
					todo.caregiverSendOrdersStandardId = $('#'+todo.caregiverId+'_select').val();
					todo.status = $('#'+todo.caregiverId+'_status').val();
					todo.nursingCostPrice = (todo.nursingCostPrice==''? 0: parseFloat(todo.nursingCostPrice));
					todo.orderStandardSalary = (todo.orderStandardSalary==''? 0: parseFloat(todo.orderStandardSalary));
					todo.status = (todo.status==''? 0: parseInt(todo.status));
				
					save_basic(path+'/caregiver/save', {caregiver:todo}, function() {
						alert('保存成功');
					});
				}
			}
		});
		
		$('#vue_vm_list div').show();
		
		for(var i=0; i<response.data.length; i++) {
			for(var j=0; j<caregiverSendOrdersStandardArray.length; j++) {
				$('#'+response.data[i].caregiverId+'_select').append('<option value="'
						+ caregiverSendOrdersStandardArray[j].caregiverSendOrdersStandardId
						+ '">' + caregiverSendOrdersStandardArray[j].standardName
						+ ' ' + caregiverSendOrdersStandardArray[j].salary + '元/天' + '</option>');
			}
			
			$('#'+response.data[i].caregiverId+'_select').val(response.data[i].caregiverSendOrdersStandardId);
		}
	});
}

function deleteBatch() {
	deleteBatch_basic(path+'/caregiver/deleteBatch');
}
